package com.server.llh.llhserverwork.activity.work;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageButton;
import android.widget.TextView;

import com.lelaohui.net.BaseLeLaohuiAcitivity;
import com.lelaohui.net.netmanager.INetRequestManager;
import com.lelaohui.net.netmanager.ServerNetRequestManager;
import com.llh.llhsuppliers.R;
import com.server.llh.llhserverwork.adapter.base.ListFragmentPagerAdapter;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by ZTF on 2017-06-28.
 * 我的任务
 */

public class MySerTaskActivity extends BaseLeLaohuiAcitivity implements TabLayout.OnTabSelectedListener{
    @BindView(R.id.main_back)
    ImageButton leftBtn;
    @BindView(R.id.titleName)
    TextView titlebarText;
    @BindView(R.id.serverName)
    TextView rightBtn;

    @BindView(R.id.id_vp_viewpager)
    ViewPager mViewPager;
    private final int FIRST_FRAGMENT = 0;
    private final int SECOND_FRAGMENT = 1;
    private final int THIRD_FRAGMENT = 2;
    private final int FOUR_FRAGMENT = 3;
    @BindView(R.id.table_layout)
    TabLayout tabLayout;
    private String[] titles=new String[]{"待执行","已执行","已撤单" };
    private ArrayList<Fragment> list = new ArrayList<Fragment>();
    ListFragmentPagerAdapter mPagerAdapter;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);

        titlebarText.setText("执行任务");
        tabLayout.setTabMode(TabLayout.MODE_FIXED);
        //循环注入标签
        for (String tab:titles){
            tabLayout.addTab(tabLayout.newTab().setText(tab));
        }
        tabLayout.setupWithViewPager(mViewPager);
        tabLayout.setOnTabSelectedListener(this);
        mViewPager = (ViewPager) findViewById(R.id.id_vp_viewpager);
        mViewPager.setOffscreenPageLimit(1);
        list.add(MySerTaskFragment.newInstance(FIRST_FRAGMENT));
        list.add(SerTaskFragment.newInstance(SECOND_FRAGMENT));
        list.add(SerTaskFragment.newInstance(THIRD_FRAGMENT));
//        list.add(SerTaskFragment.newInstance(FOUR_FRAGMENT));
        //适配器
        mPagerAdapter = new ListFragmentPagerAdapter(getSupportFragmentManager(), list, 3);
        mViewPager.setAdapter(mPagerAdapter);
        mViewPager.setOnPageChangeListener(onPageChangeListener);
        tabLayout.getTabAt(0).setText(titles[0]);
        tabLayout.getTabAt(1).setText(titles[1]);
        tabLayout.getTabAt(2).setText(titles[2]);
//        tabLayout.getTabAt(3).setText(titles[3]);
    }

    private ViewPager.OnPageChangeListener onPageChangeListener = new ViewPager.OnPageChangeListener() {

        @Override
        public void onPageSelected(int position) {
            //根据用户选中的按钮修改按钮样式
            switch (position) {
                case FIRST_FRAGMENT:

                    break;

                case SECOND_FRAGMENT:

                    break;

                case THIRD_FRAGMENT:

                    break;
                case FOUR_FRAGMENT:

                    break;
            }
        }

        @Override
        public void onPageScrolled(int arg0, float arg1, int arg2) {
        }

        @Override
        public void onPageScrollStateChanged(int arg0) {
        }
    };
    @Override
    public void onTabSelected(TabLayout.Tab tab) {

    }

    @Override
    public void onTabUnselected(TabLayout.Tab tab) {

    }

    @Override
    public void onTabReselected(TabLayout.Tab tab) {

    }
    @OnClick({R.id.main_back})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.main_back:
                onBackPressed();
                break;

        }
    }


    @Override
    protected int getlayout() {
        return R.layout.llh_query_subscribe;
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void doBasess() {

    }

    @Override
    protected INetRequestManager getRequestManager() {
        return ServerNetRequestManager.getInstance();
    }

    @Override
    public void showProgress() {
        try {

        } catch (Exception e) {

        }
    }

    @Override
    public void hideProgress() {
        try {

        } catch (Exception e) {

        }
    }


}
